package com.example.mapper;

import com.example.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {
    // 插入用户
    @Insert("INSERT INTO users(nickname, password, phone, create_time, update_time) " +
            "VALUES(#{nickname}, #{password}, #{phone}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertUser(User user);
    // 根据手机号查询用户数量
    @Select("SELECT COUNT(*) FROM users WHERE phone = #{phone}")
    int countByPhone(String phone);
    // 根据昵称查询用户数量
    @Select("SELECT COUNT(*) FROM users WHERE nickname = #{nickname}")
    int countByNickname(String nickname);
    // 根据手机号查询用户
    @Select("SELECT * FROM users WHERE phone = #{username}")
    User findByPhone(String username);
    // 根据昵称查询用户
    @Select("SELECT * FROM users WHERE nickname = #{username}")
    User findByNickname(String username);
}